﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Linq.Expressions;
using UnitHelper;

namespace IServices
{
    /// <summary>
    /// 通用接口服务类
    /// </summary>
    public interface ICommonService
    {

        #region 查询

        /// <summary>
        /// 获取所有数据
        /// </summary> 
        [DataObjectMethod(DataObjectMethodType.Select)]
        List<T> GetAllList<T>() where T : class;


        /// <summary>
        ///根据KeyId 获取实体数据 
        /// </summary> 
        [DataObjectMethod(DataObjectMethodType.Select)]
        T GetInfoByKeyId<T>(string keyId) where T : class;


        /// <summary>
        ///根据表达式获取实体数据
        /// </summary> 
        [DataObjectMethod(DataObjectMethodType.Select)]
        T GetEntity<T>(Expression<Func<T, bool>> expression) where T : class;


        /// <summary>
        ///根据表达式获取列表数据
        /// </summary> 
        [DataObjectMethod(DataObjectMethodType.Select)]
        List<T> GetListByWhere<T>(Expression<Func<T, bool>> expression) where T : class;


        /// <summary>
        /// 根据sql获取数据
        /// </summary> 
        [DataObjectMethod(DataObjectMethodType.Select)]
        List<T> GetListBySql<T>(string sql) where T : class;


        /// <summary>
        ///根据表达式获取分页数据
        /// </summary> 
        [DataObjectMethod(DataObjectMethodType.Select)]
        List<T> GetListByPage<T>(Condition condition, Expression<Func<T, bool>> expression) where T : class;


        #endregion




        #region 插入

        /// <summary>
        /// 添加新实例
        /// </summary> 
        [DataObjectMethod(DataObjectMethodType.Insert)]
        void AddEntity<T>(T entity) where T : class;


        /// <summary>
        /// 添加新实例列表
        /// </summary> 
        [DataObjectMethod(DataObjectMethodType.Insert)]
        void AddEntity<T>(IEnumerable<T> entityList) where T : class;


        #endregion



        #region 删除

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="KeyId">标识</param>
        [DataObjectMethod(DataObjectMethodType.Delete)]
        void DeleteEntity<T>(string KeyId) where T : class;

        /// <summary>
        ///根据表达式获取列表 
        /// </summary> 
        void DeleteEntityByWhere<T>(Expression<Func<T, bool>> expression) where T : class;

        #endregion


        #region 更新

        /// <summary>
        /// 更新实例
        /// </summary> 
        [DataObjectMethod(DataObjectMethodType.Update)]
        void UpdateEntity<T>(T entity) where T : class;

        /// <summary>
        /// 更新实例
        /// </summary> 
        [DataObjectMethod(DataObjectMethodType.Update)]
        void UpdateEntity<T>(IEnumerable<T> entity) where T : class;

        #endregion


    }
}
